#!/usr/bin/env node

const fs = require('fs');
const PNG = require('pngjs').PNG;

const imageData = fs.readFileSync('./images/11111.png');

var image = new PNG.sync.read(imageData);
getGrayScale(image); // 转为灰度图


function getGrayScale(image) {
    for (let y = 0; y < image.height; y++) {
      for (let x = 0; x < image.width; x++) {
        const idx = (image.width * y + x) << 2;
        const avg = (image.data[idx] + image.data[idx + 1] + image.data[idx + 2]) / 3;
        image.data[idx] = avg; // Red
        image.data[idx + 1] = avg; // Green
        image.data[idx + 2] = avg; // Blue
      }
    }
  }
  